package com.example.androidpattern.state.classes;

import android.util.Log;

import com.example.androidpattern.state.interfaces.IState;

import java.util.Random;

/**
 * @ClassName: HasMoneyState$
 * @Description: java类作用描述
 * @Author: xinya
 * @CreateDate: 2020/11/11$ 17:35$
 * @UpdateRemark: 更新内容
 * @Version: 1.0
 */
public class HasMoneyState implements IState {
    private static final String TAG = "HasMoneyState";
    private VendingMachine mMachine;

    public HasMoneyState(VendingMachine machine) {
        mMachine = machine;
    }

    @Override
    public void insertMoney() {
        Log.e(TAG, "insertMoney: 已经投币,无需再次投入");
    }

    @Override
    public void outMoney() {
        mMachine.setState(mMachine.getNoMoneyState());
        Log.d(TAG, "outMoney: 退钱成功！");
    }

    @Override
    public void chooseGoods() {
        Random random = new Random();

        if (random.nextBoolean()) {
            mMachine.setState(mMachine.getWinState());
        } else {
            mMachine.setState(mMachine.getSoldState());
        }

        Log.d(TAG, "chooseGoods: 选择商品成功");
    }

    @Override
    public void outGoods() {
        Log.e(TAG, "outGoods: 请先选择商品,才能出商品!");
    }
}
